using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Mathematics;
using Unity.VisualScripting;
using UnityEngine;
using static UnityEngine.GraphicsBuffer;

public class MoveAuthoring : MonoBehaviour  // 继承MonoBehaviour用于编辑器配置
{
    public float Speed = 5f;                    // 在Inspector中可配置的速度
    public GameObject TargetObject;             // 在Inspector中拖拽指定的目标对象
    private void Awake()
    {
        Debug.Log("MoveAuthoring");
        
    }

}

public class MoveBaker : Baker<MoveAuthoring>  // 烘焙器，将MonoBehaviour转换为ECS组件
{
    public override void Bake(MoveAuthoring authoring)
    {
        Debug.Log("Bake");
        // 获取当前GameObject对应的Entity，标记为动态（会移动的）实体
        Entity entity = GetEntity(TransformUsageFlags.Dynamic);

        AddComponent(entity, new SpeedTag
        {
            Speed = authoring.Speed,                    // 从MonoBehaviour获取速度
        });

        AddComponent(entity, new MoveDataTag
        {
            Direction = float3.zero,        // 初始方向为零向量
            DistanceToTarget = 0f,          // 初始距离为0
            IsMoving = false                // 初始不移动
        });

        if (authoring.TargetObject != null)
        {
            AddComponent(entity, new TargetTag
            {
                // 将GameObject的位置转换为float3存储
                Position = authoring.TargetObject.transform.position
            });
        }
        // 添加标签组件，标记这个实体需要执行移动逻辑
        AddComponent<MoveAuthoring>(entity);

    }
}



